home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / RESOURCES / CH20 / tommygun.cs.bak < prev    next >
Text File  |  2006-07-17  |  8KB  |  285 lines

  1. //-----------------------------------------------------------------------------
  2. // Projectile trail emitter
  3. datablock ParticleData(TommyGunSmoke)
  4. {
  5.    textureName          = "~/data/particles/smoke";
  6.  
  7.    dragCoeffiecient     = 0.0;
  8.    gravityCoefficient   = -0.2;  // rises
  9.    inheritedVelFactor   = 0.00;
  10.  
  11.    lifetimeMS           = 300;   // time in ms
  12.    lifetimeVarianceMS   = 150;   // ...more or less
  13.  
  14.    useInvAlpha = false;
  15.    spinRandomMin = -30.0;
  16.    spinRandomMax = 30.0;
  17.  
  18.    colors[0]     = "0 0.2 1 1.0";
  19.    colors[1]     = "0 0.2 1 1.0";
  20.    colors[2]     = "0 0 0 0";
  21.  
  22.    sizes[0]      = 0.25;
  23.    sizes[1]      = 0.4;
  24.    sizes[2]      = 0.6;
  25.  
  26.    times[0]      = 0.0;
  27.    times[1]      = 0.3;
  28.    times[2]      = 1.0;
  29. };
  30.  
  31. datablock ParticleEmitterData(TommyGunSmokeEmitter)
  32. {
  33.    ejectionPeriodMS = 10;
  34.    periodVarianceMS = 5;
  35.  
  36.    ejectionVelocity = 0.25;
  37.    velocityVariance = 0.10;
  38.  
  39.    thetaMin         = 0.0;
  40.    thetaMax         = 90.0;
  41.  
  42.    particles = TommyGunsmoke;
  43. };
  44.  
  45.  
  46. //-----------------------------------------------------------------------------
  47. // Weapon fire emitter
  48.  
  49. datablock ParticleData(TommyGunFireParticle)
  50. {
  51.    textureName          = "~/data/particles/smoke";
  52.  
  53.    dragCoeffiecient     = 0.0;
  54.    gravityCoefficient   = -0.1;  // rises
  55.    inheritedVelFactor   = 0.3;
  56.  
  57.    lifetimeMS           = 200;   // Time in ms
  58.    lifetimeVarianceMS   = 50;    // ...more or less
  59.  
  60.    useInvAlpha = false;
  61.    spinRandomMin = -30.0;
  62.    spinRandomMax = 30.0;
  63.  
  64.    colors[0]     = "1 0.6 1 1.0";
  65.    colors[1]     = "1 1 1 1.0";
  66.    colors[2]     = "1 0 0 0";
  67.  
  68.    sizes[0]      = 0.1;
  69.    sizes[1]      = 0.4;
  70.    sizes[2]      = 0.6;
  71.  
  72.    times[0]      = 0.0;
  73.    times[1]      = 0.3;
  74.    times[2]      = 1.0;
  75. };
  76.  
  77. datablock ParticleEmitterData(TommyGunFireEmitter)
  78. {
  79.    ejectionPeriodMS = 30;
  80.    periodVarianceMS = 5;
  81.  
  82.    ejectionVelocity = 2;
  83.    ejectionOffset   = 0.1;
  84.    velocityVariance = 0.10;
  85.  
  86.    thetaMin         = 0.0;
  87.    thetaMax         = 10.0;
  88.  
  89.    particles = TommyGunFireParticle;
  90. };
  91.  
  92.  
  93. //-----------------------------------------------------------------------------
  94. // Projectile Explosion
  95.  
  96. datablock ParticleData(TommyGunExplosionParticle)
  97. {
  98.    dragCoefficient      = 2;
  99.    gravityCoefficient   = 0.2;
  100.    inheritedVelFactor   = 0.2;
  101.    constantAcceleration = 0.0;
  102.    lifetimeMS           = 250;
  103.    lifetimeVarianceMS   = 50;
  104.    textureName          = "~/data/particles/smoke";
  105.    colors[0]     = "0.2 0.2 0.2 1.0";
  106.    colors[1]     = "0.2 0.2 0.2 0.0";
  107.    sizes[0]      = 0.1;
  108.    sizes[1]      = 0.05;
  109. };
  110.  
  111. datablock ParticleEmitterData(TommyGunExplosionEmitter)
  112. {
  113.    ejectionPeriodMS = 7;
  114.    periodVarianceMS = 0;
  115.    ejectionVelocity = 1;
  116.    velocityVariance = 1.0;
  117.    ejectionOffset   = 0.0;
  118.    thetaMin         = 0;
  119.    thetaMax         = 60;
  120.    phiReferenceVel  = 0;
  121.    phiVariance      = 360;
  122.    overrideAdvances = false;
  123.    particles = "TommyGunExplosionParticle";
  124. };
  125.  
  126. datablock ExplosionData(TommyGunExplosion)
  127. {
  128.    //explosionShape = "~/data/shapes/weapons/explosion.dts";
  129.  
  130.    particleEmitter = TommyGunExplosionEmitter;
  131.    particleDensity = 10;
  132.    particleRadius = 0.1;
  133.  
  134.    faceViewer     = true;
  135.    explosionScale = ".2 .2 .2";
  136.  
  137.    shakeCamera = false;
  138.    camShakeFreq = "10.0 11.0 10.0";
  139.    camShakeAmp = "1.0 1.0 1.0";
  140.    camShakeDuration = 0.5;
  141.    camShakeRadius = 10.0;
  142. };
  143.  
  144.  
  145. //-----------------------------------------------------------------------------
  146. // Projectile Object
  147.  
  148. datablock ProjectileData(TommyGunProjectile)
  149. {
  150.    projectileShapeName = "~/data/shapes/weapons/tgprojectile.dts";
  151.    directDamage        = 15;
  152.    radiusDamage        = 5;
  153.    damageRadius        = 0.7;
  154.    explosion           = TommyGunExplosion;
  155.   // particleEmitter     = TommyGunSmokeEmitter;
  156.  
  157.    muzzleVelocity      = 700;
  158.    velInheritFactor    = 1;
  159.  
  160.    armingDelay         = 0;
  161.    lifetime            = 2500;
  162.    fadeDelay           = 1500;
  163.    bounceElasticity    = 0;
  164.    bounceFriction      = 0;
  165.    isBallistic         = true;
  166.    gravityMod = 0.10;
  167.  
  168.    hasLight    = true;
  169.    lightRadius = 6.0;
  170.    lightColor  = "0.2 0.2 0.2";
  171. };
  172.  
  173. function TommyGunProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
  174. {
  175.    // Apply damage to the object all shape base objects
  176.    if (%col.getType() & $TypeMasks::ShapeBaseObjectType)
  177.       %col.damage(%obj,%pos,%this.directDamage,"TommyGunBullet");
  178.  
  179.    // Radius damage is a support scripts defined in radiusDamage.cs
  180.    radiusDamage(%obj,%pos,%this.damageRadius,%this.radiusDamage,"TommyGunBullet",0);
  181. }
  182.  
  183.  
  184. //-----------------------------------------------------------------------------
  185. // Ammo Item
  186.  
  187. datablock ItemData(TommyGunAmmo)
  188. {
  189.    // Mission editor category
  190.    category = "Ammo";
  191.  
  192.    // Add the Ammo namespace as a parent.  The ammo namespace provides
  193.    // common ammo related functions and hooks into the inventory system.
  194.    className = "Ammo";
  195.  
  196.    // Basic Item properties
  197.    shapeFile = "~/data/shapes/weapons/tgammo.dts";
  198.    mass = 0.5;
  199.    elasticity = 0.2;
  200.    friction = 0.4;
  201.  
  202.     // Dynamic properties defined by the scripts
  203.     pickUpName = ".45 Cal ammo";
  204.    maxInventory = 30;
  205. };
  206.  
  207.  
  208. //--------------------------------------------------------------------------
  209. // TommyGun shell that's ejected during reload.
  210.  
  211. datablock DebrisData(TommyGunShell)
  212. {
  213.    shapeFile = "~/data/shapes/weapons/tgshell.dts";
  214.    lifetime = 3.0;
  215.    minSpinSpeed = 300.0;
  216.    maxSpinSpeed = 400.0;
  217.    elasticity = 0.5;
  218.    friction = 0.2;
  219.    numBounces = 4;
  220.    staticOnMaxBounce = true;
  221.    snapOnMaxBounce = false;
  222.    fade = true;
  223. };
  224.  
  225.  
  226. //--------------------------------------------------------------------------
  227. // Weapon Item.  This is the item that exists in the world, i.e. when it's
  228. // been dropped, thrown or is acting as re-spawnable item.  When the weapon
  229. // is mounted onto a shape, the TommyGunImage is used.
  230.  
  231. datablock ItemData(TommyGun)
  232. {
  233.    // Mission editor category
  234.    category = "Weapon";
  235.  
  236.    // Hook into Item Weapon class hierarchy. The weapon namespace
  237.    // provides common weapon handling functions in addition to hooks
  238.    // into the inventory system.
  239.    className = "Weapon";
  240.  
  241.    // Basic Item properties
  242.    shapeFile = "~/data/shapes/weapons/TommyGun.dts";
  243.    mass = 1.5;
  244.    elasticity = 0.1;
  245.    friction = 0.9;
  246.    emap = true;
  247.  
  248.     // Dynamic properties defined by the scripts
  249.     pickUpName = "a sub-machinegun";
  250.     image = TommyGunImage;
  251. };
  252.  
  253.  
  254. //-----------------------------------------------------------------------------
  255.  
  256. function TommyGunImage::onFire(%this, %obj, %slot)
  257. {
  258.    %projectile = %this.projectile;
  259.  
  260.    // Decrement inventory ammo. The image's ammo state is update
  261.    // automatically by the ammo inventory hooks.
  262.    %obj.decInventory(%this.ammo,1);
  263.  
  264.    // Determin initial projectile velocity based on the
  265.    // gun's muzzle point and the object's current velocity
  266.    %muzzleVelocity = %obj.getMuzzleVector(%slot);
  267.    %objectVelocity = %obj.getVelocity();
  268.    %velocity = VectorAdd(
  269.       VectorScale(%muzzleVelocity, %projectile.muzzleVelocity),
  270.       VectorScale(%objectVelocity, %projectile.velInheritFactor));
  271.  
  272.    // Create the projectile object
  273.    %p = new (%this.projectileType)() {
  274.       dataBlock        = %projectile;
  275.       initialVelocity  = %velocity;
  276.       initialPosition  = %obj.getMuzzlePoint(%slot);
  277.       sourceObject     = %obj;
  278.       sourceSlot       = %slot;
  279.       client           = %obj.client;
  280.    };
  281.    MissionCleanup.add(%p);
  282.    return %p;
  283. }
  284.  
  285.